transformer.js ➔ ???   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 1.0004

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
dl 0
loc 22
ccs 12
cts 13
cp 0.9231
crap 1.0004
rs 9.2
nop 3

1 Function

Rating   Name   Duplication   Size   Complexity  
A transformer.js ➔ ... ➔ ??? 0 9 3
1
/**
2
 * Hapi middleware for transforming contents of request and response
3
 *
4
 * @since 1.0.0
5
 */
6
7 4
const util = require('../common/common-util');
8
9 4
const defaultOptions = Object.freeze({
10
  apiPrefix: '/api',
11
});
12
13 4
const register = (server, opts, next) => {
14 4
  const options = Object.assign({}, defaultOptions, opts);
15
  /* eslint no-param-reassign: ["error", { "props": false }] */
16 4
  server.ext('onPostAuth', (request, reply) => {
17 33
    if (request.query) {
18 33
      request.query = util.snake2camelObject(request.query);
19
    }
20 33
    if (request.payload) {
21 19
      request.payload = util.snake2camelObject(request.payload);
22
    }
23 33
    return reply.continue();
24
  });
25
26 4
  server.ext('onPreResponse', (request, reply) => {
27 26
    if (request.path.includes(options.apiPrefix)) {
28 26
      return reply(util.camel2snakeObject(request.response.source));
29
    }
30
    return reply.continue();
31
  });
32
33 4
  next();
34
};
35
36 4
register.attributes = {
37
  name: 'hapi-transform',
38
  version: '1.0.0',
39
};
40
41
module.exports = register;
42